package com.zzyl.nursing.controller.member;

import com.aliyun.iot20180120.Client;
import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.aliyun.iot20180120.models.QueryDevicePropertyStatusResponse;
import com.aliyun.iot20180120.models.QueryDevicePropertyStatusResponseBody;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.DeviceDataListDto;
import com.zzyl.common.exception.base.BaseException;
import com.zzyl.framework.config.IotClientConfig;
import com.zzyl.framework.config.properties.AliIoTConfigProperties;
import com.zzyl.nursing.domain.DeviceData;
import com.zzyl.nursing.dto.MemberUserDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.DeviceDataListVo;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.*;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author alexis
 * @date 2025-01-09
 */
@Api(tags = "老人家属管理")
@RestController
@RequestMapping("/member/user")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    @PostMapping("/login")
    public R<LoginVo> login(@RequestBody UserLoginRequestDto userLoginRequestDto) {
        // 调用Service层接口进行小程序登录
        LoginVo loginVo = familyMemberService.login(userLoginRequestDto);
        return R.ok(loginVo);
    }

    @PostMapping("/add")
    public AjaxResult bindFamilyMember(@RequestBody MemberUserDto memberUserDto) {
        familyMemberService.bindFamilyMember(memberUserDto);
        return success();
    }

    @GetMapping("/my")
    public R<List<MemberUserVo>> getMyFamilyMemberList() {
        List<MemberUserVo> memberUserVos = familyMemberService.getMyFamilyMemberList();
        return R.ok(memberUserVos);
    }

    @GetMapping("/list-by-page")
    public R<List<MemberUserPageVo>> getMyFamilyMemberListByPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                                                  @RequestParam( defaultValue = "10") Integer pageSize) {
        List<MemberUserPageVo> memberUserPageVos = familyMemberService.getMyFamilyMemberListByPage(pageNum, pageSize);
        return R.ok(memberUserPageVos);
    }

    @PostMapping("/QueryDevicePropertyStatus")
    public AjaxResult QueryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request) {
        AjaxResult ajaxResult = familyMemberService.QueryDevicePropertyStatus(request);
        return ajaxResult;
    }

    @GetMapping("/queryDeviceDataListByDay")
    public R<List<DeviceDataListVo>> queryDeviceDataListByDay(DeviceDataListDto deviceDataListDto){
        List<DeviceDataListVo> list = familyMemberService.queryDeviceDataListByDay(deviceDataListDto);
        return R.ok(list);
    }
    @GetMapping("/queryDeviceDataListByWeek")
    public R<List<DeviceDataListVo>> queryDeviceDataListByWeek(DeviceDataListDto deviceDataListDto){
        List<DeviceDataListVo> list = familyMemberService.queryDeviceDataListByWeek(deviceDataListDto);
        return R.ok(list);
    }
}
